package com.awesome.activitydemo.activities.startactivityforresult;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;

import com.awesome.activitydemo.bean.Fruit;
import com.awesome.activitydemo.R;
import com.awesome.activitydemo.utils.ActLifecycle;
import com.awesome.activitydemo.utils.ActivityManager;
import com.awesome.activitydemo.utils.MyApp;
import com.awesome.common.BuildConfig;
import com.awesome.common.util.log.ShowLogUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Author: zhangjingfang
 * Email: zhangjingfang@jeejio.com
 * Date: 2022/3/10
 * Description: startActivityForResult、onActivityResult
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ShowLogUtil.info(BuildConfig.BUILD_TYPE);
        // 构建集合数据
        List<Fruit> fruits = new ArrayList<>();
        Fruit fruit = new Fruit("apple", Color.RED);
        fruits.add(fruit);
        findViewById(R.id.tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 有返回信息的跳转页面
                Intent intent = new Intent(MainActivity.this,SecondActivity.class);
                intent.putParcelableArrayListExtra("fruits", (ArrayList<? extends Parcelable>) fruits);
                startActivityForResult(intent,0);
            }
        });
//        MyApp.instance.setOnForeListener(new ActLifecycle.onForeListener() {
//            @Override
//            public void onFore(boolean isFore) {
//                ShowLogUtil.info("isFore="+isFore);
//            }
//        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data!=null){
            String fruits = data.getStringExtra("fruits");
            ShowLogUtil.info("fruits="+fruits);
        }
    }
}